﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using NGen.Managers.Particle;

namespace XNAGameDemo.Particles {
	
	/// <summary>
	/// a sample particle which can move, rotate, be resized, and colored
	/// </summary>
	public class ExampleParticle : Particle
	{
		public Vector2 m_velocity;

		public float m_angle;

		public float m_angularVelocity;

		public Color m_colorTint;

		public float m_size;

		public float m_colorAlpha = 255;


		public ExampleParticle(Texture2D p_texture, Vector2 p_position, Vector2 p_velocity,
			float p_angle, float p_angularVelocity, Color p_color, float p_size) 
				: base(p_texture, p_position){
			m_velocity = p_velocity;
			m_angle = p_angle;
			m_angularVelocity = p_angularVelocity;
			m_colorTint = p_color;
			m_size = p_size;
		}

		public override bool Update(GameTime p_gameTime) {
			Position += m_velocity * (float)p_gameTime.ElapsedGameTime.TotalSeconds;
			m_angle += m_angularVelocity * (float)p_gameTime.ElapsedGameTime.TotalSeconds;
			m_colorAlpha -= (float)(100 * p_gameTime.ElapsedGameTime.TotalSeconds);
			m_colorTint.A = (byte)m_colorAlpha;
			
			return  (m_colorTint.A)-1 <= 0;
		}

		public override void Draw(SpriteBatch p_spriteBatch) {
			Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
			Vector2 origin = new Vector2(Texture.Width / 2f, Texture.Height / 2f);

			p_spriteBatch.Draw(Texture, Position, sourceRectangle, m_colorTint, m_angle, origin, m_size, SpriteEffects.None, 0f);
		}
	}
}
